<?php
	require 'inc.db.php';
	session_start();
	
	$_SESSION['bestelling'] = array();
	$_SESSION['producten'] = array();
	
	if(isset($_POST['productA'])){
		$_SESSION['producten'][] = 'productA';
		$_SESSION['bestelling'][] = $_POST['aantalA'] * 2;
	}
	if(isset($_POST['productB'])){
		$_SESSION['producten'][] = 'productB';
		$_SESSION['bestelling'][] = $_POST['aantalB'] * 5;
	}
	if(isset($_POST['productC'])){
		$_SESSION['producten'][] = 'productC';
		$_SESSION['bestelling'][] = $_POST['aantalC'] * 6;
	}
	if(isset($_POST['productD'])){
		$_SESSION['producten'][] = 'productD';
		$_SESSION['bestelling'][] = $_POST['aantalD'] * 7;
	}
	if(isset($_POST['productE'])){
		$_SESSION['producten'][] = 'productE';
		$_SESSION['bestelling'][] = $_POST['aantalE'] * 4;
	}
	
	$letters = array(2 => 'A', 5 => 'B', 6 => 'C', 7 => 'D', 4 => 'E');;
	foreach($letters as $key => $letter){
		if(!(empty($_POST['aantal'.$letter]))){
			if(isset($_POST['product'.$letter])){
			$_SESSION['aantal'.$letter] = $_POST['aantal'.$letter];
			}
		}
		if($_SESSION['aantal'.$letter] != 0){
			$overzicht .= '<tr><td>'.$_SESSION['aantal'.$letter].'x Product'.$letter.' &aacute; '.$key.' euro : '.$_SESSION['aantal'.$letter] * $key.' euro</td></tr>';
		}
		
		if($_SESSION['aantal'.$letter] != 0){
			$_SESSION['db_producten'] .= 'Product'.$letter.': '.$_SESSION['aantal'.$letter].', ';
		}
		
		$totaal = $totaal + ($_SESSION['aantal'.$letter] * $key);
	}
	

	$_SESSION['totaal'] = $totaal;
	
	$overzicht .= '<tr><td>Totaal: '.$_SESSION['totaal'].' euro</td></tr>';
	$overzicht .= '<tr><td><form method="post" action="'.$_SERVER['PHP_SELF'].'">
						Email: <input type="text" name="email" /><br />
						<input type="hidden" name="totaal" value="'.$totaal.'" /><br />
						<input type="submit" name="bevestig" value="Bevestig" id="bevestig" />
					</form></td></tr>';
					
	$_SESSION['overzicht'] = $overzicht;
	
					
	if(isset($_POST['bevestig'])){
		session_start();
		$email = $_POST['email'];
		if(!$email){
			$msg = '<span class="error">Geen email ingevuld</span>';
		}else{
		mysql_query("INSERT INTO bestelling SET email='$email', producten='".$_SESSION['db_producten']."', totaal='".$_POST['totaal']."', datum='".date('Y-m-d H:i:s')."'");
		$_SESSION['id'] = mysql_insert_id();
		header('Location: bedankt.php');
		}
	}
	
			
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Eindtoets</title>
<link href="../data/css/main.css" rel="stylesheet" type="text/css" />
<style type="text/css">
table{
	font-size:12px;
}

td{
	padding:5px;
}

#bevestig{
	padding:5px;
	float:right;
	margin-top:10px;
}

span.error{
	color:#F00;
	float:left;
	width:100%;
	font-size:12px;
}
</style>
</head>

<body>
<div id="main_bg"><img src="../data/images/main_bg.jpg" alt="main bg" /></div>

<div id="wrapper">
	<!-- header -->
    	<div id="header">
        	<div id="left_bow"></div>
            	<div class="placer">
                	<div id="logo"><img src="../data/images/logo.png" alt="logo" /></div>
                </div>
            <div id="right_bow"></div>
        </div>
        
       <?php include 'menu.php'; ?>
        
        <!-- content -->
    <div id="content">
        <div class="placer">
        	<!-- col left -->
        	<div id="col_left">
                <div class="field">
                    <div class="bg_top"></div>
                    <div class="bg_mid">
                        <h2>Opdracht 3</h2>
                        <p><b>Bevestiging uw bestelling</b><br />
							De volgende producten en aantallen zijn besteld:
                        </p>
                        
                        <?= $msg; ?>
                        <table border="1" cellpadding="10px" cellspacing="2">
                       	<?= $_SESSION['overzicht']; ?>
                        </table>
                    </div>
                    <div class="bg_bottom"></div>
              </div>
          </div>
          <!-- end col left -->
          
          <!-- col right -->
        	<div id="col_right">
                <div class="field">
                    <div class="bg_top"></div>
                    <div class="bg_mid">         
                        <h2 class="sec">Mijn projecten</h2>
                        <ul>
                        	<li><a href="http://tim-design.nl" target="_blank">HoeWasMijnVakantie.nl</a></li>
                            <li><a href="http://manitavoetverzorging.nl" target="_blank">Manitavoetverzorging.nl</a></li>
                            <li><a href="http://min40celsius.nl" target="_blank">Min40celsius.nl</a></li>
                            <li><a href="http://heurnsmannenkoor.nl" target="_blank">Heurnsmannenkoor.nl</a></li>
                            <li><a href="http://mytraintravels.com" target="_blank">Mytraintravels.com (in ontwikkeling)</a></li>
                            <li><a href="http://sitevisie.nl" target="_blank">Sitevisie.nl (in ontwikkeling)</a></li>
                        </ul>
                    </div>
                    <div class="bg_bottom"></div>
              </div>
          </div>
          <!-- end col right -->
        </div>
    </div>
    <!-- end content -->
</div>
</body>
</html>